package com.bbs.web.controller;

import com.bbs.domain.User;
import com.bbs.entity.Result;
import com.bbs.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.util.Map;

/**
 * @ClassName getUserController
 * @Description TODO
 * @Author chen hong wei
 * @Date 2019/9/22 11:17
 */
@RestController
@RequestMapping("/web/user")
public class getUserController {
    @Autowired
    private UserService userService;

    /**
     * @return void
     * @author chen hong wei
     * @Description 从sessin域中获取user
     * @Date 11:19 2019/9/22
     * @Param [session]
     **/
    @GetMapping("/findUser")
    public Result findUser(HttpSession session) {//
        //获取用户名
//        String username = (String) session.getAttribute("username");
        String username="test";
        if(username==null){
            return new Result(1,"请登陆");
        }
        //查询用户 根据用户名
        User user = userService.findUser(username);
        //
        Result result = new Result();
        result.setOther(user);
        return result;
    }

    @GetMapping("/update")
    public Result update(Integer userid,String username){
        if(username==null){
            return new Result(1,"请登陆");
        }
        User user = new User();
        user.setUserid(userid);
        user.setUsername(username);
        userService.update(user);
        return new Result(0,"申请成功");
    }

    @GetMapping("/findUserByLoginStatus")
    public Map<String,Object> findUserByLoginStatus(){
        return userService.findUserByLoginStatus();
    }
}